package view.geneticAlgorithmDisplays.stringGrid;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JLabel;
import javax.swing.JPanel;

import model.organism.Organism;

public class OrganismLabel extends JPanel
{
	JLabel label;
	Organism organism;
	
	@Override
	public void paintComponent(Graphics g)
	{
		label.setText(this.organism.toString());
		label.setBackground(new Color(1-organism.calculateFitness(), organism.calculateFitness(), 0.0f));
	}
	
	public OrganismLabel(Organism organism)
	{
		this.organism = organism;
		label = new JLabel(organism.toString(), JLabel.CENTER);
		label.setOpaque(true);
		this.setOpaque(true);
		this.setBackground(Color.GRAY);
		this.add(label);
	}

	public void setOrganism(Organism org)
	{
		this.organism = org;
		label.setText(this.organism.toString());
	}
	
	public Organism getOrganism()
	{
		return this.organism;
	}
	
	public String getText()
	{
		return label.getText();
	}

}
